package com.zjgsu.coursecalendar.service.impl;

import com.zjgsu.coursecalendar.exception.NotExistException;
import com.zjgsu.coursecalendar.model.Exam;
import com.zjgsu.coursecalendar.repository.ExamRepository;
import com.zjgsu.coursecalendar.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExamServiceImpl implements ExamService {
    @Autowired
    public ExamRepository examRepository;

    //得到考试信息
    @Override
    public List<Exam> getExams(int userId) {

        return examRepository.findByUserId(userId);
    }
    //添加考试信息
    @Override
    public void addExams(Exam exam) {
        examRepository.save(exam);
    }
    //删除考试信息
    @Override
    public void deleteExam(int examId) {
        if (examRepository.findOne(examId)==null){
            throw new NotExistException();
        }
        else {
            examRepository.delete(examId);
        }
    }
    //修改考试信息
    @Override
    public void updataExam(Exam exam, int examId) {
        if (examRepository.findOne(examId)==null){
            throw new NotExistException();
        }else {
            examRepository.save(exam);
        }
    }
}
